package Solutions

func solve(board [][]byte) {
	for i := 0; i < len(board[0]); i++ {
		if board[0][i] == 'O' {
			fill__(board, 0, i)
		}
		if board[len(board)-1][i] == 'O' {
			fill__(board, len(board)-1, i)
		}
	}
	for i := 0; i < len(board); i++ {
		if board[i][0] == 'O' {
			fill__(board, i, 0)
		}
		if board[i][len(board[0])-1] == 'O' {
			fill__(board, i, len(board[0])-1)
		}
	}
	for i := 0; i < len(board); i++ {
		for j := 0; j < len(board[0]); j++ {
			if board[i][j] == 1 {
				board[i][j] = 'O'
			} else {
				board[i][j] = 'X'
			}
		}
	}
}

func fill__(board [][]byte, i int, j int) {
	if i >= len(board) || i < 0 || j >= len(board[0]) || j < 0 {
		return
	}
	if board[i][j] == 'O' {
		board[i][j] = 1
		fill__(board, i-1, j)
		fill__(board, i+1, j)
		fill__(board, i, j-1)
		fill__(board, i, j+1)
	}
}
